using DiLu.Expansion.File.Configs;
using Minio;

namespace DiLu.Expansion.File.Operates.Minio.Configs;

public record SearchMinioFileConfig : SearchFileConfig
{
    /// <summary>
    ///     Minio文件搜索配置
    /// </summary>
    /// <param name="directoryFullPath">目录完整路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <param name="searchOption">搜索选项</param>
    /// <param name="searchPattern">
    ///     模糊查询模式，默认匹配所有文件
    ///     如果想查询指定类型文件使用 ^([\s\S]+)(\.(jpg|png))$
    ///     如果想模糊查询文件使用  ^([\s\S]*)name([\s\S]*)(\.\w+)$
    /// </param>
    public SearchMinioFileConfig(string directoryFullPath, IMinioClient minioClient, string bucketName,
        SearchOption searchOption = SearchOption.TopDirectoryOnly,
        string searchPattern = @"^([\s\S]+)(\.\w+)?$")
        : base(directoryFullPath, searchOption, searchPattern)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(bucketName, nameof(bucketName));
        ArgumentNullException.ThrowIfNull(minioClient, nameof(minioClient));
        MinioClient = minioClient;
        BucketName = bucketName.Trim().ToLower();
    }

    /// <summary>
    ///     Minio文件搜索配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="directoryRelativePath">目录相对路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <param name="searchOption">搜索选项</param>
    /// <param name="searchPattern">
    ///     模糊查询模式，默认匹配所有文件
    ///     如果想查询指定类型文件使用 ^([\s\S]+)(\.(jpg|png))$
    ///     如果想模糊查询文件使用  ^([\s\S]*)name([\s\S]*)(\.\w+)$
    /// </param>
    public SearchMinioFileConfig(string rootDirectory, string fileGroupName, string directoryRelativePath,
        IMinioClient minioClient, string bucketName,
        SearchOption searchOption = SearchOption.TopDirectoryOnly,
        string searchPattern = @"^([\s\S]+)(\.\w+)?$")
        : base(rootDirectory, fileGroupName, directoryRelativePath, searchOption, searchPattern)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(bucketName, nameof(bucketName));
        ArgumentNullException.ThrowIfNull(minioClient, nameof(minioClient));
        MinioClient = minioClient;
        BucketName = bucketName.Trim().ToLower();
    }

    /// <summary>
    ///     Minio客户端
    /// </summary>
    public IMinioClient MinioClient { get; }

    /// <summary>
    ///     桶名称
    /// </summary>
    public string BucketName { get; }
}